<template>
  <el-form :model="formData" label-width="120px" ref="form" v-loading="loading" class="pr-4">
    <el-form-item label="库位代号" prop="warehousecode" :rules="[{ required: true, message: '库位代号必须填写' }]">
      <el-input v-model="formData.warehousecode" name="warehousecode" clearable />
    </el-form-item>

    <el-form-item label="库位名称" prop="repositoryname" :rules="[{ required: true, message: '库位名称必须填写' }]">
      <el-input v-model="formData.repositoryname" name="repositoryname" clearable />
    </el-form-item>

    <el-form-item label="仓库负责人" prop="person" :rules="[{ required: true, message: '仓库负责人必须填写' }]">
      
      <!-- <el-input v-model="formData.person" name="person" clearable /> -->
      <el-select v-model="formData.person" placeholder="请选择仓库负责人" clearable>
        <el-option v-for="item in personArr" :key="item.id" :label="item.username" :value="item.id"   />
      </el-select>
    </el-form-item>

    <el-form-item label="所属仓库" prop="owning_id" :rules="[{ required: true, message: '所属仓库必须填写' }]">
      <el-select v-model="formData.owning_id" placeholder="请选择所属仓库" clearable>
        <el-option v-for="item in ownArr" :key="item.id" :label="item.fname" :value="item.id" />
      </el-select>
    </el-form-item>

    <el-form-item label="备注" prop="remarks" > 
      <el-input type="textarea" v-model="formData.remarks" name="remarks" clearable />
    </el-form-item>
    <div class="flex justify-end">
      <el-button type="primary" @click="submitForm(form)">{{ $t('system.confirm') }}</el-button>
      <!-- <el-button type="primary" @click="check">{{ $t('system.confirm') }}</el-button> -->
    </div>
  </el-form>
</template>

<script lang="ts" setup>
import { useCreate } from '/admin/composables/curd/useCreate'
import { useShow } from '/admin/composables/curd/useShow'
import { onMounted,ref } from 'vue'
import http from '/admin/support/http'

const props = defineProps({
  primary: String | Number,
  api: String,
})

console.log(props.api)

const ownApi = ref('/uerdataApi/warehousedataApi')

const { formData, form, loading, submitForm, close } = useCreate(props.api, props.primary)

if (props.primary) {
  useShow(props.api, props.primary, formData)
}


formData.remarks = ""

const emit = defineEmits(['close'])

const personArr = ref([])
const ownArr = ref([])

const getOptions = () => {
  http.get('warehouse/uerdataApi').then(r => {
    
    personArr.value = r.data.data
    console.log('负责人', personArr.value);

  })
  http.get('/warehouse/warehousedataApi').then(r => {
    console.log('仓库所属人',r.data.data);
    ownArr.value = r.data.data.data
  })

}


getOptions()



const check = () => {
  console.log(formData)
  console.log(form)
}

onMounted(() => {
  close(() => emit('close'))
})
</script>
